﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PSSequenceAction : PSAction {
    private PSAction[] sequence;
    private int cur = 0;

    public static PSSequenceAction GetPSAction() {
        PSSequenceAction action = ScriptableObject.CreateInstance<PSSequenceAction>();
        action.sequence = new PSAction[0];
        return action;
    }

    public void Init(PSAction[] sequence, int identifier = 0, IPSActionCallback callback = null) {
        base.Init(identifier, callback);
        this.sequence = (PSAction[])sequence.Clone();
    }

    public void Init(List<PSAction> sequence, int identifier = 0, IPSActionCallback callback = null) {
        Init(sequence.ToArray(), identifier, callback);
    }

    public override void FixedUpdate() {
        if (cur >= sequence.Length) {
            SetOver(true);
            SendCompleteEvent();
            return;
        }
        sequence[cur].FixedUpdate();
        if (sequence[cur].IsOver()) {
            ++cur;
        }
    }
}
